package cn.afterturn.easypoi.word.parse.Algorithm;

import cn.afterturn.easypoi.entity.ImageEntity;
import cn.afterturn.easypoi.util.PoiPublicUtil;
import cn.afterturn.easypoi.word.parse.excel.ExcelMapParse;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTShd;

import java.util.List;
import java.util.Map;

public class ParagraphAllBookMarkColor extends easypoiParsealgo {
    @Override
    protected void changeValues(XWPFParagraph paragraph, XWPFRun currentRun, String currentText, List<Integer> runIndex, Map<String, Object> map, String color) throws Exception{
        //判断颜色，来进行替换currenttext
        System.out.println("----进入到changevalues中，进行替换数据，bookmark是:"+currentText+"\r\n");
        //Object obj = PoiPublicUtil.getRealValue(currentText, map);
        Object obj = currentText;
        // 如果是图片就设置为图片
        if (obj instanceof ImageEntity) {
            currentRun.setText("", 0);
            ExcelMapParse.addAnImage((ImageEntity) obj, currentRun);
            //steven add
            System.out.println("替换值为图片,图片的名称为："+((ImageEntity)obj).getUrl());
        } else {
            currentText = obj.toString();
            PoiPublicUtil.setWordText(currentRun, currentText);

            CTShd cTShd = currentRun.getCTR().addNewRPr().addNewShd();
            //String color="ffff00";
            if(color!=null)
                cTShd.setFill(color);

            System.out.println("替换值为文字,文字的内容为："+currentText);
        }
        for (int k = 0; k < runIndex.size(); k++) {
            paragraph.getRuns().get(runIndex.get(k)).setText("", 0);
        }
        runIndex.clear();
    }
}
